<?php
/**
 * Created by litong on Date: 2019/2/24 0024 下午 10:37
 */
$host="localhost";$username="root";$password="";$dbname="php_study";
$connection = mysqli_connect($host, $username, $password, $dbname);
if(!$connection){
  echo mysqli_connect_error();
}

$query="INSERT INTO my_guests (firstname, lastname, email) VALUES (?, ?, ?)";
$statement = mysqli_stmt_init($connection); //初始化statement对象
if(mysqli_stmt_prepare($statement,$query)){ //编译语句
  mysqli_stmt_bind_param($statement,"sss",$firstname,$lastname,$email);//绑定参数
  // 设置参数并执行
  $firstname = 'John';$lastname = 'Doe';$email = 'john@example.com';mysqli_stmt_execute($statement);
  $firstname = 'Mary';$lastname = 'Moe';$email = 'mary@example.com';mysqli_stmt_execute($statement);
  $firstname = 'Julie';$lastname = 'Dooley';$email = 'julie@example.com';mysqli_stmt_execute($statement);
  echo "执行成功";
  mysqli_stmt_close($statement);
  mysqli_close($connection);
}else{
  echo mysqli_error();
}